-- @owner: songjing20
-- @date: 2024-7-12
-- @testpoint: connect by子句,结合order siblings by子句

--step1:创建普通表，插入数据;expect:建表成功，插入数据成功
drop table if exists t_connectby_0016 cascade;
create table t_connectby_0016(name varchar, id int, fatherid int);
insert into t_connectby_0016 values('A', 1, 0), ('B', 2, 1),('C',3,1),('D',4,1),('E',5,2),('F',0,1),('G',1,2);

--step2:结合order siblings by子句，查询id=1作为初始集合的递归查询，进行排序;expect:成功
select * from t_connectby_0016 start with id=1 connect by nocycle prior id = fatherid order siblings by id asc;

--step3:结合层次递归查询函数查看递归层级;expect:成功
select sys_connect_by_path(name,'-') as path, *, level from t_connectby_0016 connect by nocycle prior id = fatherid order siblings by id desc;

--step4:siblings by+limit子句;expect:成功
select * from t_connectby_0016 start with id=1 connect by nocycle prior id = fatherid order siblings by id asc limit 3;
select sys_connect_by_path(name,'-') as path, *, level from t_connectby_0016
connect by nocycle prior id = fatherid order siblings by id desc limit 10;

--step5:清理环境;expect:成功
drop table t_connectby_0016 cascade;
